from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-25 14:16:11.978297
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 25, Oct, 2022
Time: 14:16:17
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.8165
Nobs: 820.000 HQIC: -51.1350
Log likelihood: 10664.9 FPE: 5.08398e-23
AIC: -51.3334 Det(Omega_mle): 4.55854e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.292701 0.051928 5.637 0.000
L1.Burgenland 0.108838 0.035164 3.095 0.002
L1.Kärnten -0.106368 0.018732 -5.678 0.000
L1.Niederösterreich 0.211030 0.073583 2.868 0.004
L1.Oberösterreich 0.101383 0.070499 1.438 0.150
L1.Salzburg 0.249514 0.037422 6.667 0.000
L1.Steiermark 0.037994 0.049041 0.775 0.438
L1.Tirol 0.106330 0.039771 2.674 0.008
L1.Vorarlberg -0.058085 0.034202 -1.698 0.089
L1.Wien 0.061009 0.062910 0.970 0.332
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.064442 0.107402 0.600 0.549
L1.Burgenland -0.033126 0.072729 -0.455 0.649
L1.Kärnten 0.047838 0.038744 1.235 0.217
L1.Niederösterreich -0.173014 0.152190 -1.137 0.256
L1.Oberösterreich 0.385463 0.145813 2.644 0.008
L1.Salzburg 0.286053 0.077400 3.696 0.000
L1.Steiermark 0.105083 0.101430 1.036 0.300
L1.Tirol 0.313709 0.082257 3.814 0.000
L1.Vorarlberg 0.025396 0.070740 0.359 0.720
L1.Wien -0.015216 0.130116 -0.117 0.907
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.187775 0.026663 7.043 0.000
L1.Burgenland 0.090685 0.018055 5.023 0.000
L1.Kärnten -0.008385 0.009618 -0.872 0.383
L1.Niederösterreich 0.264924 0.037781 7.012 0.000
L1.Oberösterreich 0.125644 0.036198 3.471 0.001
L1.Salzburg 0.048232 0.019215 2.510 0.012
L1.Steiermark 0.017599 0.025180 0.699 0.485
L1.Tirol 0.094755 0.020420 4.640 0.000
L1.Vorarlberg 0.059552 0.017561 3.391 0.001
L1.Wien 0.120141 0.032301 3.719 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.107107 0.027322 3.920 0.000
L1.Burgenland 0.044893 0.018502 2.426 0.015
L1.Kärnten -0.016157 0.009856 -1.639 0.101
L1.Niederösterreich 0.193412 0.038716 4.996 0.000
L1.Oberösterreich 0.293264 0.037094 7.906 0.000
L1.Salzburg 0.116100 0.019690 5.896 0.000
L1.Steiermark 0.100124 0.025803 3.880 0.000
L1.Tirol 0.117019 0.020926 5.592 0.000
L1.Vorarlberg 0.070801 0.017996 3.934 0.000
L1.Wien -0.027109 0.033100 -0.819 0.413
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121653 0.049667 2.449 0.014
L1.Burgenland -0.050460 0.033633 -1.500 0.134
L1.Kärnten -0.040391 0.017916 -2.254 0.024
L1.Niederösterreich 0.170298 0.070378 2.420 0.016
L1.Oberösterreich 0.136455 0.067429 2.024 0.043
L1.Salzburg 0.285342 0.035793 7.972 0.000
L1.Steiermark 0.034191 0.046905 0.729 0.466
L1.Tirol 0.165960 0.038038 4.363 0.000
L1.Vorarlberg 0.105014 0.032712 3.210 0.001
L1.Wien 0.073762 0.060170 1.226 0.220
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060180 0.039273 1.532 0.125
L1.Burgenland 0.039311 0.026594 1.478 0.139
L1.Kärnten 0.050773 0.014167 3.584 0.000
L1.Niederösterreich 0.225298 0.055650 4.048 0.000
L1.Oberösterreich 0.282395 0.053318 5.296 0.000
L1.Salzburg 0.051489 0.028302 1.819 0.069
L1.Steiermark -0.008072 0.037089 -0.218 0.828
L1.Tirol 0.149788 0.030078 4.980 0.000
L1.Vorarlberg 0.071049 0.025867 2.747 0.006
L1.Wien 0.078739 0.047579 1.655 0.098
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.172396 0.046978 3.670 0.000
L1.Burgenland -0.005198 0.031812 -0.163 0.870
L1.Kärnten -0.061119 0.016947 -3.607 0.000
L1.Niederösterreich -0.083007 0.066569 -1.247 0.212
L1.Oberösterreich 0.192073 0.063779 3.012 0.003
L1.Salzburg 0.057479 0.033855 1.698 0.090
L1.Steiermark 0.230296 0.044366 5.191 0.000
L1.Tirol 0.494992 0.035980 13.758 0.000
L1.Vorarlberg 0.050274 0.030942 1.625 0.104
L1.Wien -0.046259 0.056913 -0.813 0.416
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.158336 0.053876 2.939 0.003
L1.Burgenland -0.011195 0.036483 -0.307 0.759
L1.Kärnten 0.065906 0.019435 3.391 0.001
L1.Niederösterreich 0.200824 0.076343 2.631 0.009
L1.Oberösterreich -0.060280 0.073144 -0.824 0.410
L1.Salzburg 0.216997 0.038826 5.589 0.000
L1.Steiermark 0.113799 0.050880 2.237 0.025
L1.Tirol 0.077905 0.041262 1.888 0.059
L1.Vorarlberg 0.124931 0.035485 3.521 0.000
L1.Wien 0.114612 0.065270 1.756 0.079
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.350570 0.031430 11.154 0.000
L1.Burgenland 0.006221 0.021283 0.292 0.770
L1.Kärnten -0.023579 0.011338 -2.080 0.038
L1.Niederösterreich 0.224732 0.044536 5.046 0.000
L1.Oberösterreich 0.173890 0.042670 4.075 0.000
L1.Salzburg 0.047997 0.022650 2.119 0.034
L1.Steiermark -0.016108 0.029682 -0.543 0.587
L1.Tirol 0.109592 0.024071 4.553 0.000
L1.Vorarlberg 0.074108 0.020701 3.580 0.000
L1.Wien 0.053640 0.038077 1.409 0.159
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041425 0.152936 0.189697 0.159038 0.124039 0.115257 0.066208 0.227344
Kärnten 0.041425 1.000000 -0.002731 0.129518 0.041986 0.096233 0.429097 -0.053089 0.100952
Niederösterreich 0.152936 -0.002731 1.000000 0.338049 0.156621 0.299875 0.112886 0.184905 0.329530
Oberösterreich 0.189697 0.129518 0.338049 1.000000 0.233551 0.332129 0.174004 0.173195 0.264014
Salzburg 0.159038 0.041986 0.156621 0.233551 1.000000 0.146317 0.130436 0.149846 0.136340
Steiermark 0.124039 0.096233 0.299875 0.332129 0.146317 1.000000 0.153366 0.140791 0.078912
Tirol 0.115257 0.429097 0.112886 0.174004 0.130436 0.153366 1.000000 0.116005 0.156642
Vorarlberg 0.066208 -0.053089 0.184905 0.173195 0.149846 0.140791 0.116005 1.000000 0.008468
Wien 0.227344 0.100952 0.329530 0.264014 0.136340 0.078912 0.156642 0.008468 1.000000